package com.company.Sort;

import java.io.*;
import java.util.Arrays;
import java.util.Random;

/**
 * Created by v on 16-12-10.
 */
public class Main {
    public static void main(String[] args) throws IOException{
        int max=100000;

        long sum1=0;
        long sum2=0;
        long sum3=0;

        for(int i=0;i<20;i++){
            Integer[] list=new Integer[50000];
            Random random=new Random();
            for(int j=0;j<list.length;j++){
                list[j]=random.nextInt();
            }

            //克隆出三个相同的list
            Integer[] list1=list.clone();
            Integer[] list2=list.clone();
            Integer[] list3=list.clone();

            //选择排序
            long time=System.currentTimeMillis();
            InsertionSort.insertionSort(list1);
            System.out.println("选择排序: "+(System.currentTimeMillis()-time));
            sum1+=System.currentTimeMillis()-time;

            //归并排序
            time=System.currentTimeMillis();
            MergeSort.mergeSort(list2);
            System.out.println("归并排序: "+(System.currentTimeMillis()-time));
            sum2+=System.currentTimeMillis()-time;

            //快速排序
            time=System.currentTimeMillis();
            QuickSort.quickSort(list3);
            System.out.println("快速排序: "+(System.currentTimeMillis()-time));
            sum3+=System.currentTimeMillis()-time;

            System.out.println();
        }

        System.out.println("选择排序平均时间: "+sum1/20.0);
        System.out.println("归并排序平均时间: "+sum2/20.0);
        System.out.println("快速排序平均时间: "+sum3/20.0);
    }
}
